import router from './router'
import store from './store'
import { Message } from 'element-ui'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import { getToken } from '@/utils/auth'

NProgress.configure({ showSpinner: false })

const whiteList = ['/index']

router.beforeEach((to, from, next) => {
  NProgress.start()

    /* has token*/
    if (to.path === '/tool') {
      NProgress.done()
    } else {
      // 判断当前用户是否已拉取完user_info信息
      store.dispatch('GetInfo').then(res => {
        next()
      }).catch(err => {
          Message({
            type:'error',
            message: err || "出现错误，请稍后再试"
          })
            next({ path: '/' })
          })
    }

})

router.afterEach(() => {
  NProgress.done()
})
